import requests
import os
url = 'https://pvp.qq.com/web201605/js/herolist.json'
herolist = requests.get(url)
herolist_json = herolist.json()
print(herolist_json)
#获取英雄名称
hero_name = list(map(lambda x:x['cname'],herolist_json))
#获取英雄编号
# hero_skin_name = list(map(lambda x:x['skin_name'],herolist_json))
# # print(hero_skin_name)
for z in herolist_json:
    print(z['skin_name'])
hero_number = list(map(lambda x:x['ename'],herolist_json))
def downloadpic():
    i = 0
    for j in hero_number:
        #创建每个英雄的文件夹
        # os.mkdir("C:\\Users\\hqc\\Desktop\\wzry" + str(hero_number[i]))
        # os.chdir("C:\\Users\\hqc\\Desktop\\wzry" + str(hero_number[i]))
        os.mkdir("C:\\Users\\hqc\\Desktop\\"  + "wzry\\" + hero_name[i])
        os.chdir("C:\\Users\\hqc\\Desktop\\" + "wzry\\" + hero_name[i])
        print("正在下载%s的高清大图"%hero_name[i])
        i += 1
        for k in range(10):
            #每个英雄所对应图片的请求链接
            #//game.gtimg.cn/images/yxzj/img201606/skin/hero-info/167/167-bigskin-1.jpg
            hero_link = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + str(j) + '/' + str(j) + '-bigskin-' + str(k)+ '.jpg'
            #hero_link = 'http://game.gtimg.cn/images/yxzj/img201606/heroimg/' + str(j) + '/' + str(j) + '-smallskin-' + str(k) + '.jpg'
            im = requests.get(hero_link)
            if im.status_code == 200:
                open(str(k) + '.jpg', 'wb').write(im.content)
downloadpic()



